﻿<!-- #Include File="../Include/Admin_Onlogin.asp" -->
<%
Dim sqlAuth, rsAuth, PurviewID
sqlAuth = "Select AuthID From Admin_Auth Where href='Admin/Admin_SqlData.asp' Order By sort Asc,AuthID Asc"
Call Exec(rsAuth,sqlAuth,2)
If rsAuth.BOF And rsAuth.EOF Then
	PurviewID = 0
Else
	PurviewID = rsAuth(0)
	CheckPurview PurviewID,0
End If
rsAuth.Close
Set rsAuth = Nothing
Response.Write "<!DOCTYPE html>" & vbCrLf
Response.Write "<head>" & vbCrLf
Response.Write "<title>数据库在线管理</title>" & vbCrlf
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" & vbCrLf
Response.Write "<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>" & vbCrLf
Response.Write "<meta name='apple-mobile-web-app-status-bar-style' content='black'>" & vbCrLf
Response.Write "<meta name='apple-mobile-web-app-capable' content='yes'>" & vbCrLf
Response.Write "<meta name='format-detection' content='telephone=no'>" & vbCrLf
Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""../fonts/font-awesome/css/font-awesome.min.css"" />" & vbCrLf
Response.Write "<link href='../Plugins/layui/css/layui.css' rel='stylesheet' type='text/css' />" & vbCrLf
Response.Write "<link rel=""stylesheet"" href=""../Style/global.css"" media=""all"">" & vbCrLf
Response.Write "<link rel=""stylesheet"" href=""../Style/font.css"" media=""all"">" & vbCrLf
Response.Write "<script type='text/javascript'>" & vbCrLf
Response.Write "var pc_file = '" & InstallDir & "';" & vbCrLf
Response.Write "var admin_file = '" & AdminFolder & "/';" & vbCrLf
Response.Write "</script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../Js/Admin.js'></script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../../Dialog/main.js'></script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../../Dialog/lhgcore.min.js'></script>" & vbCrLf
Response.Write "<script type='text/javascript' src='../../Dialog/lhgcalendar.min.js'></script>" & vbCrLf
Response.Write "<script type=""text/javascript"" src=""../Plugins/layui/layui.js""></script>" & vbCrLf
Response.Write "</head>" & vbCrlf
Response.Write "<body>" & vbCrlf
Response.Write "<div class=""admin-main layui-anim layui-anim-upbit"">" & vbCrLf
Response.Write "    <fieldset class=""layui-elem-field layui-field-title"">" & vbCrlf
Response.Write "        <legend>数据库在线管理</legend>" & vbCrlf
Response.Write "    </fieldset>" & vbCrlf
Response.Write "    <blockquote class=""layui-elem-quote"">" & vbCrlf
Response.Write "        <a href=""?"" class=""layui-btn layui-btn-sm"">数据库在线管理</a>" & vbCrlf
Response.Write "    </blockquote>" & vbCrlf
Select Case Action
Case "Create"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/AddTable' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Create()
Case "Table"
    Call Table()
Case "Add"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/Insert' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Add()
Case "Modify"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/Update' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Modify()
Case "Exe"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/Sql' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Exe()
Case "Del"
	sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/Del' Order By sort Asc,AuthID Asc"
	Call Exec(rsAuth,sqlAuth,2)
	If rsAuth.BOF And rsAuth.EOF Then
		CheckPurview 0,0
	Else
		CheckPurview rsAuth(0),0
	End If
	rsAuth.Close
	Set rsAuth = Nothing
    Call Del()
Case "ToSql"
	If Request("Strt") = "0" Or Request("Strt") = "2" Then
		sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/ToTable' Order By sort Asc,AuthID Asc"
		Call Exec(rsAuth,sqlAuth,2)
		If rsAuth.BOF And rsAuth.EOF Then
			CheckPurview 0,0
		Else
			CheckPurview rsAuth(0),0
		End If
		rsAuth.Close
		Set rsAuth = Nothing
	ElseIf Request("Strt") = "1" Or Request("Strt") = "3" Then
		sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/ToSql' Order By sort Asc,AuthID Asc"
		Call Exec(rsAuth,sqlAuth,2)
		If rsAuth.BOF And rsAuth.EOF Then
			CheckPurview 0,0
		Else
			CheckPurview rsAuth(0),0
		End If
		rsAuth.Close
		Set rsAuth = Nothing
	End If
    Call ToSql(Request("Strt"))
Case "ReObj"
	If Request("Obj") = "field" Then   '修改字段名
		sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/EditFidle' Order By sort Asc,AuthID Asc"
		Call Exec(rsAuth,sqlAuth,2)
		If rsAuth.BOF And rsAuth.EOF Then
			CheckPurview 0,0
		Else
			CheckPurview rsAuth(0),0
		End If
		rsAuth.Close
		Set rsAuth = Nothing
	ElseIf Request("Obj") = "Table" Then   '修改表名
		sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/EditTable' Order By sort Asc,AuthID Asc"
		Call Exec(rsAuth,sqlAuth,2)
		If rsAuth.BOF And rsAuth.EOF Then
			CheckPurview 0,0
		Else
			CheckPurview rsAuth(0),0
		End If
		rsAuth.Close
		Set rsAuth = Nothing
	ElseIf Request("Obj") = "Sql" Then
		
	ElseIf Request("Obj") = "KeyName" Then   '设为主键
		sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/Key' Order By sort Asc,AuthID Asc"
		Call Exec(rsAuth,sqlAuth,2)
		If rsAuth.BOF And rsAuth.EOF Then
			CheckPurview 0,0
		Else
			CheckPurview rsAuth(0),0
		End If
		rsAuth.Close
		Set rsAuth = Nothing
	ElseIf Request("Obj") = "CreateKey" Then   '设为主键
		sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/CreateKey' Order By sort Asc,AuthID Asc"
		Call Exec(rsAuth,sqlAuth,2)
		If rsAuth.BOF And rsAuth.EOF Then
			CheckPurview 0,0
		Else
			CheckPurview rsAuth(0),0
		End If
		rsAuth.Close
		Set rsAuth = Nothing
	ElseIf Request("Obj") = "DeleteKey" Then   '删除主键
		sqlAuth = "Select AuthID From Admin_Auth Where pid="&PurviewID&" And href='SqlData/DeleteKey' Order By sort Asc,AuthID Asc"
		Call Exec(rsAuth,sqlAuth,2)
		If rsAuth.BOF And rsAuth.EOF Then
			CheckPurview 0,0
		Else
			CheckPurview rsAuth(0),0
		End If
		rsAuth.Close
		Set rsAuth = Nothing
	End If
    Call ReObj()
Case Else
    Call Main()
End Select
If FoundErr = True Then
	Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</div></body>" & vbCrLf & "</html>"
Call CloseConn()

Sub Main()
	Response.Write "<br>" & vbCrlf
	Response.Write "<div class=""table-responsive"">" & vbCrLf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;""><img src=""../images/table.gif"" align=""absmiddle"">&nbsp;数据库中的表：<a href=""Admin_SqlData.asp?Action=ToSql&Strt=2"">导出所有表结构到SQL</a>&nbsp;&nbsp;<a href=""Admin_SqlData.asp?Action=ToSql&Strt=3"">导出所有表内容到SQL</a><br>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	dim rsSchema,str
	set rsSchema=Conn.OpenSchema(20)
	rsSchema.movefirst
	Response.Write"<table width='100%' border='0' cellpadding='0' cellspacing='0'>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	i = 1
	While not rsSchema.EOF
		If rsSchema("TABLE_TYPE")="TABLE" Then
			If rsSchema("Description")<>"" Then
				Response.Write "<td align=center><a href=""Admin_SqlData.asp?Action=Table&TableName="&rsSchema("TABLE_NAME")&"""><img border=""0"" src=""../images/table.gif"" width=""23"" height=""19"" align=""absmiddle""><br>"&rsSchema("TABLE_NAME")&" ("&rsSchema("Description")&")</a></td>" & vbCrlf
			Else
				Response.Write "<td align=center><a href=""Admin_SqlData.asp?Action=Table&TableName="&rsSchema("TABLE_NAME")&"""><img border=""0"" src=""../images/table.gif"" width=""23"" height=""19"" align=""absmiddle""><br>"&rsSchema("TABLE_NAME")&"</a></td>" & vbCrlf
			End If
			If (i Mod 6) = 0 Then Response.Write "</tr>"  & vbCrlf & "<tr>" & vbCrlf
			i=i+1
		End If
		rsSchema.movenext
	Wend
	Response.Write "</tr>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	Response.Write "</td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	Response.Write "</div>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<div class=""table-responsive"">" & vbCrLf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td height=""22"" align=""center""><strong>创建新表</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<form name=""form1"" method=""post"" action=""Admin_SqlData.asp?Action=Create"">" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td align=""center"">表名：<input type=""text"" name=""TableName"">&nbsp;<button type=""submit"" class=""layui-btn"" hidefocus=""true"">创  建==></button></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</form>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td>注：test表为对不熟悉Access库操作的用户所建，可以在线任意修改，以熟练对表的操作，对其它的表的操作要慎重!</td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	Response.Write "</div>" & vbCrlf
End Sub

Sub Table()
	dim TableName
	TableName=Trim(Request.QueryString("TableName"))
	If(len(TableName)<1) Then
		Response.Write IsSuccess("请指定正确的表名！",AdminFolder & "/Admin/Admin_SqlData.asp")
		Response.End()
	End If
	On Error Resume Next
	Response.Write "<br>" & vbCrlf
	Response.Write "<div class=""table-responsive"">" & vbCrLf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td height=""22"" align=""center""><strong>" & TableName & "表：</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;"">" & vbCrlf
	Set Cat = Server.CreateObject("ADOX.Catalog")
	Set Fld = Server.CreateObject("ADOX.Column")
	Cat.ActiveConnection=Conn
	Set Primary = Conn.OpenSchema(28,Array(empty, empty, TableName))
	If Primary("COLUMN_NAME") <> "" Then
		do while not Primary.EOF
			PrimaryKey = PrimaryKey & Primary("COLUMN_NAME") & ","
			Primary.MoveNext
		loop
	End If
	Primary.Close
	Set Primary = Nothing
	sql="Select Top 1 * From [" & TableName & "]"
	Call Exec(rs,sql,2)
	Response.Write "字段总数："&rs.fields.count&"&nbsp;&nbsp;<a href=""Admin_SqlData.asp?Action=ToSql&Strt=0&TableName="&TableName&""">导出表结构</a>&nbsp;&nbsp;<a href=""Admin_SqlData.asp?Action=ToSql&Strt=1&TableName="&TableName&""">导出表内容</a>&nbsp;&nbsp;<a style=""cursor:pointer;"" onClick=""IsConfirm('确认删除该记录吗？<br>该操作将不可撤销！','"&InstallDir&AdminFolder&"/Admin/Admin_SqlData.asp?Action=ReObj&Obj=Sql&Sql=DROP TABLE "&TableName&"','');"">删除表</a><br><br>" & vbCrlf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td align=""center""><strong>序</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>字段名称</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>字段属性</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>设定大小</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>默认值</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>允许空</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>自动编号</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>主键</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>描述</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>修改</strong></td>" & vbCrlf
	Response.Write "<td align=""center""><strong>删除</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	for i=0 to rs.fields.count-1
		Set Fld = Cat.Tables(TableName).Columns(rs(i).name)
		if Instr(PrimaryKey, rs(i).name)>0 then IsPrimaryKey = True else IsPrimaryKey = False end if
		Response.Write "<tr>" & vbCrlf
		Response.Write "<td align=""center"">"&i+1&"</td>" & vbCrlf
		Response.Write "<td align=""center"">"
		if IsPrimaryKey = True then Response.Write "<img src=""../images/key.gif"" border=""0"" width=""16"" height=""16"" onmouseover=""layer.tips('主键栏',this,{tips: [1, '#000']});"" onmouseout=""layer.closeAll();"">&nbsp;"
		Response.Write rs(i).name&"</td>" & vbCrlf
		Response.Write "<td align=""center"">" & FieldType(rs(i).Type) & "</td>" & vbCrlf
		Response.Write "<td align=""center"">"
		If Cat.Tables(TableName).Columns(rs(i).name).DefinedSize > 0 Then Response.Write Cat.Tables(TableName).Columns(rs(i).name).DefinedSize
		Response.Write "</td>" & vbCrlf
		Response.Write "<td>" & Cat.Tables(TableName).Columns(rs(i).name).Properties("Default").Value & "</td>" & vbCrlf
		Response.Write "<td align=""center"">" & iif((rs(i).Attributes and &H00000020)=0,"No","Yes") & "</td>" & vbCrlf
		Response.Write "<td align=""center"">" & iif(rs(i).Properties("ISAUTOINCREMENT") = True,"是","否") & "</td>" & vbCrlf
		Response.Write "<td align=""center"">"
		if IsPrimaryKey = True then
			Response.Write "<a href=""Admin_SqlData.asp?Action=ReObj&Obj=DeleteKey&TableName=" & TableName & "&field=" & rs(i).name & "&PrimaryKey=" & PrimaryKey & """><img src=""../images/un_key.gif"" border=""0"" width=""16"" height=""16"" onmouseover=""layer.tips('删除主键',this,{tips: [1, '#000']});"" onmouseout=""layer.closeAll();""></a>"
		else
			Response.Write "<a href=""Admin_SqlData.asp?Action=ReObj&Obj=CreateKey&TableName=" & TableName & "&field=" & rs(i).name & "&PrimaryKey=" & PrimaryKey & """><img src=""../images/key.gif"" border=""0"" width=""16"" height=""16"" onmouseover=""layer.tips('设为主键',this,{tips: [1, '#000']});"" onmouseout=""layer.closeAll();""></a>"
		end if
		Response.Write "</td>" & vbCrlf
		Response.Write "<td>" & Cat.Tables(TableName).Columns(rs(i).name).Properties("Description").Value & "</td>" & vbCrlf
		Response.Write "<td align=""center""><a href=""Admin_SqlData.asp?Action=Table&TableName="&TableName&"&Key=EditFidle&fidle="&rs.fields(i).name&"&fidletype="&FieldType(rs(i).type)&""">修改</a></td>" & vbCrlf
		Response.Write "<td align=""center""><a style=""cursor:pointer;"" onClick=""IsConfirm('确认删除？并且不能恢复！确定要删除这个字段？','" & InstallDir & AdminFolder & "/Admin/Admin_SqlData.asp?Action=Del&fieldname="&rs.fields(i).name&"&TableName="&TableName&"','');"">删除</a></td>" & vbCrlf
		Response.Write "</tr>" & vbCrlf
		EditStr = EditStr & "_data.push(['"&rs(i).name&"','"&rs(i).name&"']);"
	next
	Response.Write "</table>" & vbCrlf
	If PrimaryKey = "" Then
		Response.Write "<br>" & vbCrlf
		Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
		Response.Write "<tr class=""title"">" & vbCrlf
		Response.Write "<td align=""center""><strong>设为主键</strong></td>" & vbCrlf
		Response.Write "</tr>" & vbCrlf
		Response.Write "<form name=""form_mod"" method=""post"" action=""Admin_SqlData.asp?Action=ReObj&Obj=KeyName&TableName=" & TableName & """ style=""margin:0; padding:0;"">" & vbCrlf
		Response.Write "<tr>" & vbCrlf
		Response.Write "<td style=""padding:10px;"" align=""center""><font color=red>该表没有主键，执行操作可能会导致数据损坏或丢失。</font><br>"
		Response.Write "你可以将："
		Response.Write "<div id=""keyname_outer"" ztype=""select"" class=""z-combox"" style=""display:inline-block; *zoom: 1;*display: inline;vertical-align:middle;height:auto;width:auto;position:relative;border:none 0;margin:0;padding:0;white-space: nowrap;"" _style=""width:200px;""><input type=""text"" ztype=""select"" id=""keyname"" name=""keyname"" tabindex=""-1"" autocomplete=""off"" class=""inputText"" style=""width:200px;position:absolute;z-index:-1;"" onchange=""changeClassType(this.options[this.selectedIndex].value);"" value="""" startvalue=""""/><input type=""text"" id=""keyname_textField"" autocomplete=""off"" class=""inputText"" style=""vertical-align:middle; cursor:default;width:200px;"" /><a id=""keyname_spinner"" class=""z-combox-spinner"" style=""position:relative; left:-17px; margin-right:-15px; cursor:pointer; width:13px; height:15px;vertical-align:middle;""><b></b></a><div id=""keyname_list"" class=""optgroup"" style=""text-align:left;display:none;""><div id=""keyname_ul"" style=""left:-1px; width:-1px;""><script>Combox_keyname_Init=function(){var _el=Zving.getDom('keyname');if(_el._components){return true;}var  _data=[];var  _DataSource;"
		For i=0 To rs.fields.count-1
			Response.Write "_data.push(['" & rs(i).name & "','" & rs(i).name & "']);"
		Next
		Response.Write "var combox_keyname = new Zving.Selector({el:_el,data:_data,DataSource:_DataSource});};if(Zving.Page.isReady){Combox_keyname_Init();}else{Zving.Page.onReady(Combox_keyname_Init);}</script></div></div></div>&nbsp;<button type=""submit"" class=""layui-btn"" hidefocus=""true"">设为主键</button></td>" & vbCrlf
		Response.Write "</tr>" & vbCrlf
		Response.Write "</form>" & vbCrlf
		Response.Write "</table>"
	End If
	Response.Write "<br>" & vbCrlf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td align=""center""><strong>修改表名</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<form name=""form_mod"" method=""post"" action=""Admin_SqlData.asp?Action=ReObj&Obj=Table&TableName=" & TableName & """ style=""margin:0; padding:0;"">" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;"" align=""center""><input type=""text"" name=""newtablename"" size=""20"" value=""" & TableName & """>&nbsp;<button type=""submit"" class=""layui-btn"" hidefocus=""true"">修改表名</button></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</form>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td align=""center""><strong>修改字段名</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<form name=""form_mod"" method=""post"" action=""Admin_SqlData.asp?Action=ReObj&Obj=field&TableName=" & TableName & """ style=""margin:0; padding:0;"">" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;"" align=""center"">" & vbCrlf
	'显示修改字段名
	Response.Write "<div id=""fieldsname_outer"" ztype=""select"" class=""z-combox"" style=""display:inline-block; *zoom: 1;*display: inline;vertical-align:middle;height:auto;width:auto;position:relative;border:none 0;margin:0;padding:0;white-space: nowrap;"" _style=""width:200px;""><input type=""text"" ztype=""select"" id=""fieldsname"" name=""fieldsname"" tabindex=""-1"" autocomplete=""off"" class=""inputText"" style=""width:200px;position:absolute;z-index:-1;"" onchange=""changeClassType(this.options[this.selectedIndex].value);"" value=""" & ofieldsname & """ startvalue=""" & ofieldsname & """/><input type=""text"" id=""fieldsname_textField"" autocomplete=""off"" class=""inputText"" style=""vertical-align:middle; cursor:default;width:200px;"" /><a id=""fieldsname_spinner"" class=""z-combox-spinner"" style=""position:relative; left:-17px; margin-right:-15px; cursor:pointer; width:13px; height:15px;vertical-align:middle;""><b></b></a><div id=""fieldsname_list"" class=""optgroup"" style=""text-align:left;display:none;""><div id=""fieldsname_ul"" style=""left:-1px; width:-1px;""><script>Combox_fieldsname_Init=function(){var _el=Zving.getDom('fieldsname');if(_el._components){return true;}var  _data=[];var  _DataSource;"
	Response.Write "_data.push(['','选择字段']);"
	Response.Write EditStr
	Response.Write "var combox_fieldsname = new Zving.Selector({el:_el,data:_data,DataSource:_DataSource});};if(Zving.Page.isReady){Combox_fieldsname_Init();}else{Zving.Page.onReady(Combox_fieldsname_Init);}</script></div></div></div> 改名为" & vbCrlf
	Response.Write "<input type='text' name='newfieldsname' size='20'>&nbsp;<button type=""submit"" class=""layui-btn"" hidefocus=""true"">修改字段名</button>"
	Response.Write "</td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</form>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	rs.close
	set rs=nothing
	If Trim(Request("Key"))="EditFidle" Then
		sql = "Select * From [" & TableName & "]"
		Call Exec(rs,sql,2)
		For i = 0 to rs.fields.count - 1
			If rs(i).name = Request("fidle") Then
				Response.Write "<br>" & vbCrlf
				Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
				Response.Write "<tr class=""title"">" & vbCrlf
				Response.Write "<td align=""center""><strong>修改字段属性</strong></td>" & vbCrlf
				Response.Write "</tr>" & vbCrlf
				Response.Write "<tr>" & vbCrlf
				Response.Write "<td style=""padding:10px;"" align=""center""><table class=""layui-table table-hover"">" & vbCrlf
				Response.Write "<form name=""form_mod"" method=""post"" action=""Admin_SqlData.asp?Action=Modify&TableName=" & TableName & """ style=""margin:0; padding:0;"">" & vbCrlf
				Response.Write "<tr class=""title"">" & vbCrlf
				Response.Write "<td width=""20%"" align=""center""><strong>字段名</strong></td>" & vbCrlf
				Response.Write "<td width=""20%"" align=""center""><strong>类型</strong></td>" & vbCrlf
				Response.Write "<td width=""10%"" align=""center""><strong>设定大小</strong></td>" & vbCrlf
				Response.Write "<td width=""10%"" align=""center""><strong>默认值</strong></td>" & vbCrlf
				Response.Write "<td width=""10%"" align=""center""><strong>允许空值</strong></td>" & vbCrlf
				Response.Write "<td width=""10%"" align=""center""><strong>自动编号</strong></td>" & vbCrlf
				Response.Write "<td width=""10%"" align=""center""><strong>描述</strong></td>" & vbCrlf
				Response.Write "<td width=""10%"" align=""center""><strong>操作</strong></td>" & vbCrlf
				Response.Write "</tr>" & vbCrlf
				Response.Write "<tr>" & vbCrlf
				Response.Write "<td align=""center""><input name=""fieldname"" type=""text"" size=""20"" maxlength=""25"" value=""" & rs(i).name & """></td>" & vbCrlf
				Response.Write "<td align=""center"">" & FieldTypeList(Request("fidletype"),"fieldtype") & "</td>" & vbCrlf
				Response.Write "<td align=""center""><input type=""text"" name=""size"" size=""10"" value="""
				If Cat.Tables(TableName).Columns(rs(i).name).DefinedSize > 0 Then Response.Write Cat.Tables(TableName).Columns(rs(i).name).DefinedSize Else Response.Write "-1"
				Response.Write """></td>" & vbCrlf
				Response.Write "<td align=""center""><input type=""text"" name=""default"" value=""" & Replace(Cat.Tables(TableName).Columns(rs(i).name).Properties("Default").Value,Chr(34),"&quot;") & """></td>" & vbCrlf
				Response.Write "<td align=""center""><input type=""checkbox"" name=""null"" value=""null""" & iif((rs(i).Attributes and &H00000020)=0,""," checked") & "></td>" & vbCrlf
				Response.Write "<td align=""center""><input type=""checkbox"" name=""autoincrement"" value=""y""" & iif(rs(i).Properties("ISAUTOINCREMENT") = True," checked","") & "></td>" & vbCrlf
				Response.Write "<td align=""center""><input type=""text"" name=""description"" value=""" & Replace(Cat.Tables(TableName).Columns(rs(i).name).Properties("Description").Value,Chr(34),"&quot;") & """></td>" & vbCrlf
				Response.Write "<td width=""20%"" align=""center""><button type=""submit"" class=""layui-btn"" hidefocus=""true"">修 改</button></td>" & vbCrlf
				Response.Write "</tr>" & vbCrlf
				Response.Write "</form>" & vbCrlf
				Response.Write "</table></td>" & vbCrlf
				Response.Write "</tr>" & vbCrlf
				Response.Write "</table>" & vbCrlf
			End If
		Next
	End If
	Response.Write "<br>" & vbCrlf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td align=""center""><strong>添加新字段</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;"" align=""center""><table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<form name=""form_mod"" method=""post"" action=""Admin_SqlData.asp?Action=Add&TableName=" & TableName & """ style=""margin:0; padding:0;"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td width=""20%"" align=""center""><strong>字段名</strong></td>" & vbCrlf
	Response.Write "<td width=""20%"" align=""center""><strong>类型</strong></td>" & vbCrlf
	Response.Write "<td width=""10%"" align=""center""><strong>设定大小</strong></td>" & vbCrlf
	Response.Write "<td width=""10%"" align=""center""><strong>默认值</strong></td>" & vbCrlf
	Response.Write "<td width=""10%"" align=""center""><strong>允许空值</strong></td>" & vbCrlf
	Response.Write "<td width=""10%"" align=""center""><strong>自动编号</strong></td>" & vbCrlf
	Response.Write "<td width=""10%"" align=""center""><strong>描述</strong></td>" & vbCrlf
	Response.Write "<td width=""10%"" align=""center""><strong>操作</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td align=""center""><input name=""fieldname"" type=""text"" size=""20"" maxlength=""25""></td>" & vbCrlf
	Response.Write "<td align=""center"">" & FieldTypeList("","fieldtype2") & "</td>" & vbCrlf
	Response.Write "<td align=""center""><input type=""text"" name=""fldsize"" size=""10"" value=""""></td>" & vbCrlf
	Response.Write "<td align=""center""><input type=""text"" name=""default"" value=""""></td>" & vbCrlf
	Response.Write "<td align=""center""><input name=""null"" type=""checkbox"" value=""ON"" checked></td>" & vbCrlf
	Response.Write "<td align=""center""><input type=""checkbox"" name=""autoincrement"" value=""ON""></td>" & vbCrlf
	Response.Write "<td align=""center""><input type=""text"" name=""description"" value=""""></td>" & vbCrlf
	Response.Write "<td width=""20%"" align=""center""><button type=""submit"" class=""layui-btn"" hidefocus=""true"">添 加</button></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</form>" & vbCrlf
	Response.Write "</table></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	Response.Write "<br>" & vbCrlf
	Response.Write "<table class=""layui-table table-hover"">" & vbCrlf
	Response.Write "<tr class=""title"">" & vbCrlf
	Response.Write "<td align=""center""><strong>执行SQL语句</strong></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;"">" & vbCrlf
	Response.Write "SQL 常用语句：<br><br>"
	Response.Write "创建表：<br>"
	Response.Write "CREATE TABLE [表名] (<br>"
	Response.Write "[test1] int not null identity,<br>"
	Response.Write "[test2] binary not null,<br>"
	Response.Write "primary key ([test1]))<br><br>"
	Response.Write "设置主键：ALTER TABLE [tablename] ADD PRIMARY KEY ([fieldname])<br><br>"
	Response.Write "查询：select * from tablename where fieldname *** order by id desc<br><br>"
	Response.Write "更新：update tanlename set fieldname = values,cn_name='values' where ID = 1<br><br>"
	Response.Write "添加：insert into tanlename (fieldnam,fieldnam2)values (1,'values')<br><br>"
	Response.Write "删除：delete from tanlename where fieldname = values<br><br>"
	Response.Write "删除表：DROP TABLE 数据表名称<br><br>"
	Response.Write "添加字段：ALTER TABLE [表名] ADD [字段名] NVARCHAR (50) NULL<br><br>"
	Response.Write "删除字段：alter table [tablename] drop [fieldname]<br><br>"
	Response.Write "修改字段：ALTER TABLE [表名] ALTER COLUMN [字段名] 类型(大小) NULL<br><br>"
	Response.Write "新建约束：ALTER TABLE [表名] ADD CONSTRAINT 约束名 CHECK ([约束字段] <= '2000-1-1')<br><br>"
	Response.Write "删除约束：ALTER TABLE [表名] DROP CONSTRAINT 约束名<br><br>"
	Response.Write "新建默认值：ALTER TABLE [表名] ADD CONSTRAINT 默认值名 DEFAULT '默认值' FOR [字段名]<br><br>"
	Response.Write "删除默认值：ALTER TABLE [表名] DROP CONSTRAINT 默认值名<br><br>"
	Response.Write "</td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;"" align=""center""><table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">" & vbCrlf
	Response.Write "<form name=""form1"" method=""post"" action=""Admin_SqlData.asp?Action=Exe&TableName=" & TableName & """ style=""margin:0; padding:0; "">" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td align=""center""><textarea name=""sqlexe"" cols=""80"" rows=""10"" id=""sqlexe"">在此处输入sql语句，注：请慎用此功能!</textarea></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td align=""center""><button type=""submit"" class=""layui-btn"" hidefocus=""true"">执 行</button></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</form>" & vbCrlf
	Response.Write "</table></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</table></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	Response.Write "</div>" & vbCrlf
	Response.Write "<script>" & vbCrlf
	Response.Write "layui.use(['form'], function () {" & vbCrlf
	Response.Write "    var form = layui.form;" & vbCrlf
	Response.Write "});" & vbCrlf
	Response.Write "</script>" & vbCrlf
End Sub

Sub Create()
	dim TableName
	TableName=Trim(Request.Form("TableName"))
	If(len(TableName)<1) Then
		Response.Write IsSuccess("请输入表名！",AdminFolder & "/Admin/Admin_SqlData.asp")
		Response.End()
	End If
	Call Exec("","CREATE TABLE [" & TableName & "] (ID AUTOINCREMENT(1,1))",0)
	Call Exec("","CREATE INDEX [PrimaryKey] ON [" & TableName & "]([ID]) WITH PRIMARY",0)
	Response.Write IsSuccess("操作成功！",AdminFolder & "/Admin/Admin_SqlData.asp")
End Sub

Sub Add()
	dim addsql
	dim TableName,fieldname,fieldtype2,sqlexe,charlen
	TableName=Trim(Request.QueryString("TableName"))
	If(len(TableName)<1) Then
		Response.Write IsSuccess("请指定正确的表名！",AdminFolder & "/Admin/Admin_SqlData.asp")
		Response.End()
	End If
	fieldname=Trim(Request.Form("fieldname"))
	If(len(fieldname)<1) Then
		Response.Write IsSuccess("请指定正确的字段名！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
		Response.End()
	End If
	fieldtype2=Trim(Request.Form("fieldtype2"))
	If(len(fieldtype2)<1) Then
		Response.Write IsSuccess("请指定正确的字段类型！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
		Response.End()
	End If
	sql = "Alter Table "&TableName&" Add "&fieldname&" "&fieldtype2
	If Request.Form("fldsize") <> "" Then
		sql = sql & " (" & Request.Form("fldsize") & ")"
	End If 
	If Request.Form("null") <> "ON" Then
		sql = sql & " not null"
	End If
	If Request.Form("autoincrement") = "ON" Then
		sql = sql & " identity"
	End If
	Call Exec("",sql,0)
	On Error Resume Next
	Set Cat = Server.CreateObject("ADOX.Catalog")
	Set Fld = Server.CreateObject("ADOX.Column")
	Cat.ActiveConnection=Conn
	Cat.Tables(TableName).Columns(fieldname).Type = Request.Form("fieldtype2")
	Cat.Tables(TableName).Columns(fieldname).DefinedSize = Request.Form("fldsize")
	Cat.Tables(TableName).Columns(fieldname).Properties("Default").Value = Request.Form("default")
	Cat.Tables(TableName).Columns(fieldname).Properties("Description").Value = Request.Form("description")
	Response.Write IsSuccess("成功为表："&TableName&"添加字段："&fieldname&"！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
End Sub

Sub Modify()
	dim addsql
	dim TableName,fieldname,fieldtype,sqlexe,charlen
	TableName=Trim(Request.QueryString("TableName"))
	If(len(TableName)<1) Then
		Response.Write IsSuccess("请指定正确的表名！",AdminFolder & "/Admin/Admin_SqlData.asp")
		Response.End()
	End If
	fieldname=Trim(Request.Form("fieldname"))
	If(len(fieldname)<1) Then
		Response.Write IsSuccess("请指定正确的字段名！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
		Response.End()
	End If
	fieldtype=Trim(Request.Form("fieldtype"))
	If(len(fieldtype)<1) Then
		Response.Write IsSuccess("请指定正确的字段类型！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
		Response.End()
	End If
	sql = "Alter Table [" & TableName & "] ALTER COLUMN [" & fieldname & "] "
	If fieldtype <> "" Then
		sql = sql & " " & fieldtype
	End If
	If Request.Form("size") <> "" And Request.Form("size") <> "-1" Then
		sql = sql & " (" & Request.Form("size") & ")"
	End If
	If Request.Form("null") = "" Then
		sql = sql & " not null"
	End If
	If Request.Form("autoincrement") = "y" Then
		sql = sql & " identity"
	End If
	Call Exec("",sql,0)
	On Error Resume Next
	Set Cat = Server.CreateObject("ADOX.Catalog")
	Set Fld = Server.CreateObject("ADOX.Column")
	Cat.ActiveConnection=Conn
	Cat.Tables(TableName).Columns(fieldname).Type = Request.Form("fieldtype")
	Cat.Tables(TableName).Columns(fieldname).DefinedSize = Request.Form("size")
	Cat.Tables(TableName).Columns(fieldname).Properties("Default").Value = Request.Form("default")
	Cat.Tables(TableName).Columns(fieldname).Properties("Description").Value = Request.Form("description")
	Response.Write IsSuccess("成功为表："&TableName&"修改字段："&fieldname&"！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
End Sub

Sub Del()
	dim TableName
	TableName=Trim(Request.QueryString("TableName"))
	If(len(TableName)<1) Then
		Response.Write IsSuccess("请指定正确的表名！",AdminFolder & "/Admin/Admin_SqlData.asp")
		Response.End()
	End If
	fieldname=Trim(Request.QueryString("fieldname"))
	If(len(fieldname)<1) Then
		Response.Write IsSuccess("请指定正确的字段名！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
		Response.End()
	End If
	Call Exec("","ALTER TABLE "&TableName&" DROP COLUMN "&fieldname,0)
	Response.Write IsSuccess("成功为表："&TableName&"删除字段："&fieldname&"！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
End Sub

Sub Exe()
	dim TableName
	sqlexe=Trim(Request.Form("sqlexe"))
	TableName=Trim(Request.QueryString("TableName"))

	If(len(sqlexe)<1) Then
		Response.Write IsSuccess("请指定正确的字段名！",AdminFolder & "/Admin/Admin_SqlData.asp?Action=Table&TableName="&TableName&"")
		Response.End()
	End If
	Call Exec("",sqlexe,0)
	Response.Write IsSuccess("成功执行SQL语句！",AdminFolder & "/Admin/Admin_SqlData.asp")
End Sub

Sub ReObj()
	On Error Resume Next
	Dim mydb,mytable,TableName
	TableName = Request("TableName")
	Set mydb = Server.CreateObject("ADOX.Catalog")
	Set Fld = Server.CreateObject("ADOX.Column")
	mydb.ActiveConnection = Conn
	
	If Request("Obj") = "field" Then   '修改字段名
		dim fieldsname,newfieldsname
		fieldsname = Request.Form("fieldsname")
		newfieldsname = Request.Form("newfieldsname")
		Set mytable = Server.CreateObject("ADOX.Table")
		Set mytable = mydb.Tables(TableName)
		mytable.Columns(fieldsname).Name = newfieldsname
	End If
	
	If Request("Obj") = "Table" Then   '修改表名
		dim newtablename
		newtablename = Request.Form("newtablename")
		mydb.Tables(TableName).Name = newtablename
	End If
	
	If Request("Obj") = "Sql" Then
		Call Exec("",Request("Sql"),0)
	End If
	
	If Request("Obj") = "KeyName" Then   '设为主键
		Call Exec("","CREATE INDEX [PrimaryKey] ON [" & Request("TableName") & "]([" & Trim(Request.Form("keyname")) & "]) WITH PRIMARY",0)
	End If
	
	If Request("Obj") = "CreateKey" Then   '设为主键
		If InStr(Request("PrimaryKey"), ",") > 0 Then
			str = ""
			arrFieldList = Split(Request("PrimaryKey"), ",")
			For i = 0 To UBound(arrFieldList)
				If Trim(arrFieldList(i)) <> "" and Trim(arrFieldList(i)) <> Request("field") and i<>UBound(arrFieldList) Then
					str = str & "[" & arrFieldList(i) & "],"
				End If
			Next
		End If
		If Len(str) > 0 then
			Call Exec("","DROP INDEX [PrimaryKey] ON [" & Request("TableName") & "]",0)
		End If
		Call Exec("","CREATE INDEX [PrimaryKey] ON [" & Request("TableName") & "](" & Replace(str,"[" & Request("field") & "],","",1,-1,1) & "[" & Request("field") & "]) WITH PRIMARY",0)
	End If
	
	If Request("Obj") = "DeleteKey" Then   '删除主键
		Call Exec("","DROP INDEX [PrimaryKey] ON [" & Request("TableName") & "]",0)
		If InStr(Request("PrimaryKey"), ",") > 0 Then
			str = ""
			arrFieldList = Split(Request("PrimaryKey"), ",")
			For i = 0 To UBound(arrFieldList)
				If Trim(arrFieldList(i)) <> "" and Trim(arrFieldList(i)) <> Request("field") and i<>UBound(arrFieldList) Then
					str = str & "[" & arrFieldList(i) & "],"
				End If
			Next
		End If
		If Len(str) > 0 then
			str = Left(str, Len(str) - 1)
			Call Exec("","CREATE INDEX [PrimaryKey] ON [" & Request("TableName") & "](" & Replace(str,"[" & Request("field") & "],","",1,-1,1) & ") WITH PRIMARY",0)
		End If
	End If
	
	If err <> 0 Then
		Response.Redirect "Admin_SqlData.asp?Action=Table&TableName=" & TableName
		Exit Sub
	End If
	
	If Request("Obj") = "field" Then
		Response.Redirect "Admin_SqlData.asp?Action=Table&TableName=" & TableName
	ElseIf Request("Obj") = "Sql" Then
		If TableName<>"" Then
			Response.Redirect "Admin_SqlData.asp?Action=Table&TableName=" & TableName
		Else
			Response.Redirect "Admin_SqlData.asp"
		End If
	ElseIf Request("Obj") = "KeyName" Then
		If TableName<>"" Then
			Response.Redirect "Admin_SqlData.asp?Action=Table&TableName=" & TableName
		Else
			Response.Redirect "Admin_SqlData.asp"
		End If
	ElseIf Request("Obj") = "CreateKey" Then
		If TableName<>"" Then
			Response.Redirect "Admin_SqlData.asp?Action=Table&TableName=" & TableName
		Else
			Response.Redirect "Admin_SqlData.asp"
		End If
	ElseIf Request("Obj") = "DeleteKey" Then
		If TableName<>"" Then
			Response.Redirect "Admin_SqlData.asp?Action=Table&TableName=" & TableName
		Else
			Response.Redirect "Admin_SqlData.asp"
		End If
	Else
		Response.Redirect "Admin_SqlData.asp?Action=Table&TableName=" & newtablename
	End If
End Sub

Sub ToSql(Strt)
	'Strt = 0 导出结构
	'Strt = 1 导出内容
	Dim StrSql
	If Strt = "0"  Then
		TableName = Request("TableName")
		Response.Write "<br><table class=""layui-table table-hover"">" & vbCrlf
		Response.Write "<tr class=""title"">" & vbCrlf
		Response.Write "<td height=""30"" align=""center"">以下是表 <font color=red>" & Request("TableName") & "</font> 的结构:<button type=""button"" class=""layui-btn"" hidefocus=""true"" onClick=""javascript:history.back();"">返 回</button></td>" & vbCrlf
		Response.Write "</tr>" & vbCrlf
		StrSql = GetSql(TableName)
	End If
	If Strt = "1"  Then
		TableName = Request("TableName")
		Response.Write "<br><table class=""layui-table table-hover"">" & vbCrlf
		Response.Write "<tr class=""title"">" & vbCrlf
		Response.Write "<td height=""30"" align=""center"">以下是表 <font color=red>" & Request("TableName") & "</font> 的内容:<button type=""button"" class=""layui-btn"" hidefocus=""true"" onClick=""javascript:history.back();"">返 回</button></td>" & vbCrlf
		Response.Write "</tr>" & vbCrlf
		StrSql = GetData(TableName)
	End If
	If Strt = "2" Then
		Response.Write "<br><table class=""layui-table table-hover"">" & vbCrlf
		Response.Write "<tr class=""title"">" & vbCrlf
		Response.Write "<td height=""30"" align=""center"">以下是 <font color=red> 数据库 </font> 的结构:<button type=""button"" class=""layui-btn"" hidefocus=""true"" onClick=""javascript:history.back();"">返 回</button></td>" & vbCrlf
		Response.Write "</tr>" & vbCrlf
		set objSchema = Conn.OpenSchema(20)
		Do While Not objSchema.EOF
			If objSchema("TABLE_TYPE") = "TABLE" Then
				TableName = objSchema("TABLE_NAME")
				StrSql = StrSql & GetSql(TableName)'TableName & "|"'GetSql(TableName)
			End If
		objSchema.MoveNext
		Loop
		objSchema.close
	End If
	If Strt = "3" Then
		Response.Write "<br><table class=""layui-table table-hover"">" & vbCrlf
		Response.Write "<tr class=""title"">" & vbCrlf
		Response.Write "<td height=""30"" align=""center"">以下是 <font color=red> 数据库 </font> 的结构:<button type=""button"" class=""layui-btn"" hidefocus=""true"" onClick=""javascript:history.back();"">返 回</button></td>" & vbCrlf
		Response.Write "</tr>" & vbCrlf
		set objSchema = Conn.OpenSchema(20)
		Do While Not objSchema.EOF
			If objSchema("TABLE_TYPE") = "TABLE" Then
				TableName = objSchema("TABLE_NAME")
				StrSql = StrSql & GetData(TableName)'TableName & "|"'GetData(TableName)
			End If
		objSchema.MoveNext
		Loop
		objSchema.close
	End If
	Response.Write "</tr>" & vbCrlf
	Response.Write "<tr>" & vbCrlf
	Response.Write "<td style=""padding:10px;"" align=""center""><textarea cols='100' rows='38'>" & StrSql & "</textarea></td>" & vbCrlf
	Response.Write "</tr>" & vbCrlf
	Response.Write "</table>" & vbCrlf
	Conn.Close
End Sub

Function GetSql(TableName)
	On Error Resume Next
	GetSql = "-- 表结构 " & TableName & " 的SQL语句。" & chr(10)
	dim primary,primarykey
	Set primary = Conn.OpenSchema(28,Array(empty,empty,TableName))
	If primary("COLUMN_NAME") <> "" Then
		primarykey = primary("COLUMN_NAME")
	End If
	
	primary.Close
	set primary = nothing
	
	tbl_struct = "CREATE TABLE [" & TableName & "] ( " & chr(10)
	sql = "Select * From [" & TableName & "]"
	Call Exec(rs,sql,2)
	If err = 0 Then
		for i = 0 to rs.fields.count-1
		   tbl_struct = tbl_struct & "[" & rs(i).name & "] "
		   typs = FieldType(rs(i).type)
		   If typs = "VARCHAR" or typs = "BINARY" or typs = "CHAR" Then
			 tbl_struct = tbl_struct & typs & "(" & rs(i).definedsize & ")"
		   else
			 tbl_struct = tbl_struct & typs & " "
		   End If
		   attrib = rs(i).attributes
		   If (attrib and &H00000020) = 0 Then
			 tbl_struct = tbl_struct&" NOT NULL"
		   End If
		   If rs(i).Properties("ISAUTOINCREMENT") = True Then
			 tbl_struct = tbl_struct & " IDENTITY"
		   End If
		   tbl_struct = tbl_struct & "," & chr(10)
		next
		If primarykey <> "" Then
			tbl_struct = tbl_struct & "PRIMARY KEY ([" & primarykey & "]));"
		else
			len_of_sql = Len(tbl_struct)
			tbl_struct = Mid(tbl_struct,1,len_of_sql-2)
			tbl_struct = tbl_struct & ");"
		End If
	else
		tbl_struct = "CREATE TABLE [" & TableName & "];"
	End If
	GetSql = GetSql & tbl_struct & chr(10) & chr(10)
End Function

Function GetData(TableName)
	On Error Resume Next
	Sql = "Select * From [" & TableName & "]"
	Call Exec(Rs,Sql,2)
	If Rs.BOF And Rs.EOF Then
	Else
		GetData = "-- 表内容 " & TableName & " 的SQL语句。" & chr(10)
		Do While Not Rs.Eof
			tbl_struct = tbl_struct & "INSERT INTO `"&TableName&"` ("
			for i=0 to Rs.fields.count-1
				If i=0 Then
					tbl_struct = tbl_struct & "`"&Rs(i).name&"`"
				Else
					tbl_struct = tbl_struct & ", `"&Rs(i).name&"`"
				End If
			next
			tbl_struct = tbl_struct & ") VALUES ("
			for i=0 to Rs.fields.count-1
				If i=0 Then
					If IsNull(Rs(Rs(i).name)) Then
						tbl_struct = tbl_struct & "NULL"
					Else
						If rs(i).Type = 3 Or rs(i).Type = 4 Or rs(i).Type = 5 Or rs(i).Type = 11 Then
							tbl_struct = tbl_struct & ReSql(Rs(Rs(i).name))
						ElseIf rs(i).Type = 7 Or rs(i).Type = 135 Then
							tbl_struct = tbl_struct & "'" & ReSql(Time_Type(Rs(Rs(i).name),1)) & "'"
						Else
							tbl_struct = tbl_struct & "'" & ReSql(Rs(Rs(i).name)) & "'"
						End If
					End If
				Else
					If IsNull(Rs(Rs(i).name)) Then
						tbl_struct = tbl_struct & ",NULL"
					Else
						If rs(i).Type = 3 Or rs(i).Type = 4 Or rs(i).Type = 5 Or rs(i).Type = 11 Then
							tbl_struct = tbl_struct & "," & ReSql(Rs(Rs(i).name))
						ElseIf rs(i).Type = 7 Or rs(i).Type = 135 Then
							tbl_struct = tbl_struct & ",'" & ReSql(Time_Type(Rs(Rs(i).name),1)) & "'"
						Else
							tbl_struct = tbl_struct & ",'" & ReSql(Rs(Rs(i).name)) & "'"
						End If
					End If
				End If
			next
			tbl_struct = tbl_struct & ")" & chr(10) & chr(10)
			Rs.MoveNext
		Loop
	End If
	GetData = GetData & tbl_struct
End Function

Function IIf(var, val1, val2)
	If var = True Then
		IIf = val1
	Else
		IIf = val2
	End If
End Function

Function FieldTypeList(n,fieldtype)
	dim StrList,Str1,Str2
	StrList = "<div id="""&fieldtype&"_outer"" ztype=""select"" class=""z-combox"" style=""display:inline-block; *zoom: 1;*display: inline;vertical-align:middle;height:auto;width:auto;position:relative;border:none 0;margin:0;padding:0;white-space: nowrap;"" _style=""width:200px;""><input type=""text"" ztype=""select"" id="""&fieldtype&""" name="""&fieldtype&""" tabindex=""-1"" autocomplete=""off"" class=""inputText"" style=""width:200px;position:absolute;z-index:-1;"" onchange=""changeClassType(this.options[this.selectedIndex].value);"" value=""" & n & """ startvalue=""" & n & """/><input type=""text"" id="""&fieldtype&"_textField"" autocomplete=""off"" class=""inputText"" style=""vertical-align:middle; cursor:default;width:200px;"" /><a id="""&fieldtype&"_spinner"" class=""z-combox-spinner"" style=""position:relative; left:-17px; margin-right:-15px; cursor:pointer; width:13px; height:15px;vertical-align:middle;""><b></b></a><div id="""&fieldtype&"_list"" class=""optgroup"" style=""text-align:left;display:none;""><div id="""&fieldtype&"_ul"" style=""left:-1px; width:-1px;""><script>Combox_"&fieldtype&"_Init=function(){var _el=Zving.getDom('"&fieldtype&"');if(_el._components){return true;}var  _data=[];var  _DataSource;"
	If SystemDatabaseType = 0 Then
		StrList = StrList & "_data.push(['','选择类型']);"
		StrList = StrList & "_data.push(['VarChar','文本']);"
		StrList = StrList & "_data.push(['Text','备注']);"
		StrList = StrList & "_data.push(['Bit','(是/否)']);"
		StrList = StrList & "_data.push(['TinyInt','数字(字节)']);"
		StrList = StrList & "_data.push(['SmallInt','数字(整型)']);"
		StrList = StrList & "_data.push(['Integer','数字(长整型)']);"
		StrList = StrList & "_data.push(['Single','数字(单精度)']);"
		StrList = StrList & "_data.push(['Double','数字(双精度)']);"
		StrList = StrList & "_data.push(['Numeric','数字(小数)']);"
		StrList = StrList & "_data.push(['GUID','数字(同步ID)']);"
		StrList = StrList & "_data.push(['DateTime','时间/日期']);"
		StrList = StrList & "_data.push(['Money','货币']);"
		StrList = StrList & "_data.push(['Binary','二进制']);"
		StrList = StrList & "_data.push(['LongBinary','长二进制']);"
		StrList = StrList & "_data.push(['LongBinary','OLE 对象']);"
	Else
		StrList = StrList & "_data.push(['','选择类型']);"
		StrList = StrList & "_data.push(['BigInt','bigint']);"
		StrList = StrList & "_data.push(['Binary','binary(二进制数据类型)']);"
		StrList = StrList & "_data.push(['Bit','bit(整型)']);"
		StrList = StrList & "_data.push(['Char','char(字符型)']);"
		StrList = StrList & "_data.push(['DateTime','datetime(日期时间型)']);"
		StrList = StrList & "_data.push(['Decimal','decimal(精确数值型)']);"
		StrList = StrList & "_data.push(['Float','float(近似数值型)']);"
		StrList = StrList & "_data.push(['Image','image(二进制数据类型)']);"
		StrList = StrList & "_data.push(['Int','int(整型)']);"
		StrList = StrList & "_data.push(['Money','money(货币型)']);"
		StrList = StrList & "_data.push(['nchar','nchar(统一编码字符型)']);"
		StrList = StrList & "_data.push(['ntext','ntext(统一编码字符型)']);"
		StrList = StrList & "_data.push(['numeric','numeric(精确数值型)']);"
		StrList = StrList & "_data.push(['nvarchar','nvarchar(统一编码字符型)']);"
		StrList = StrList & "_data.push(['real','real(近似数值型)']);"
		StrList = StrList & "_data.push(['smalldatetime','Smalldatetime(日期时间型)']);"
		StrList = StrList & "_data.push(['smallint','smallint(整型)']);"
		StrList = StrList & "_data.push(['smallmoney','smallmoney(货币型)']);"
		StrList = StrList & "_data.push(['sql_variant','sql_variant()']);"
		StrList = StrList & "_data.push(['text','text(字符型)']);"
		StrList = StrList & "_data.push(['timestamp','timestamp(特殊数据型)']);"
		StrList = StrList & "_data.push(['tinyint','tinyint(整型)']);"
		StrList = StrList & "_data.push(['uniqueidentifier','Uniqueidentifier(特殊数据型)']);"
		StrList = StrList & "_data.push(['varbinary','varbinary(二进制数据类型)']);"
		StrList = StrList & "_data.push(['varchar','varchar(字符型)']);"
	End If
	StrList = StrList & "var combox_"&fieldtype&" = new Zving.Selector({el:_el,data:_data,DataSource:_DataSource});};if(Zving.Page.isReady){Combox_"&fieldtype&"_Init();}else{Zving.Page.onReady(Combox_"&fieldtype&"_Init);}</script></div></div></div>"
	FieldTypeList = StrList
End Function

Function FieldType(field_type)
	'field_type = 字段类型值
	Select Case field_type
		Case 0:FieldType = "Empty"
		Case 16:FieldType = "TinyInt"
		Case 2:FieldType = "SmallInt"
		Case 3:FieldType = "Integer"
		Case 20:FieldType = "BigInt"
		Case 17:FieldType = "TinyInt" 'UnsignedTinyInt
		Case 18:FieldType = "UnsignedSmallInt"
		Case 19:FieldType = "UnsignedInt"
		Case 21:FieldType = "UnsignedBigInt"
		Case 4:FieldType = "Single" 'Single
		Case 5:FieldType = "Double" 'Double
		Case 6:FieldType = "Money" 'Currency
		Case 14:FieldType = "Decimal"
		Case 131:FieldType = "Numeric" 'Numeric
		Case 11:FieldType = "Bit" 'Boolean
		Case 10:FieldType = "Error"
		Case 132:FieldType = "UserDefined"
		Case 12:FieldType = "Variant"
		Case 9:FieldType = "IDispatch"
		Case 13:FieldType = "IUnknown"
		Case 72:FieldType = "GUID" 'GUID
		Case 7:FieldType = "DateTime" 'Date
		Case 133:FieldType = "DBDate"
		Case 134:FieldType = "DBTime"
		Case 135:FieldType = "DateTime" 'DBTimeStamp
		Case 8:FieldType = "BSTR"
		Case 129:FieldType = "Char"
		Case 200:FieldType = "VarChar"
		Case 201:FieldType = "LongVarChar"
		Case 130:FieldType = "Text"  'WChar类型 SQL中为Text
		Case 202:FieldType = "VarChar" 'VarWChar
		Case 203:FieldType = "Text" 'LongVarWChar
		Case 128:FieldType = "Binary"
		Case 204:FieldType = "VarBinary"
		Case 205:FieldType = "LongBinary"'LongVarBinary
		Case 136:FieldType = "Chapter"
		Case 138:FieldType = "PropVariant"
		Case else:FieldType = "Unknown"
	End Select
End Function

Public Function ReSql(ByVal HtmlStr)
	ReSql = HtmlStr
	ReSql = Replace(ReSql,"True",1,1,-1,1)
	ReSql = Replace(ReSql,"False",0,1,-1,1)
	ReSql = Replace(ReSql,chr(13)&chr(10),"\r\n",1,-1,1)
	ReSql = Replace(ReSql,chr(10),"|",1,-1,1)
End Function
%>